import 'package:flutter/material.dart';

class WidgetSpanDemo extends StatelessWidget {
  const WidgetSpanDemo({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("WidgetSpan"),
      ),
      body: Container(
        child: Column(
          children: [
            RichText(
              text: TextSpan(
                  style: TextStyle(color: Colors.blueGrey, fontSize: 22),
                  text: "AA",
                  children: [
                    TextSpan(text: "BB", style: TextStyle(fontSize: 26)),
                    TextSpan(
                        text: "www.163.com",
                        style: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 32)),
                  ]),
            ),
            Divider(),
            Text.rich(
                TextSpan(style: TextStyle(color: Colors.blueGrey), children: [
              TextSpan(text: "Flutter is"),
              WidgetSpan(
                  child: SizedBox(
                width: 120,
                height: 50,
                child: Card(child: Center(child: Text("Hello World!"))),
              )),
              TextSpan(text: "the best!"),
            ])),
            Divider(),
            Text.rich(
                TextSpan(style: TextStyle(color: Colors.blueGrey), children: [
              TextSpan(text: "Flutter is"),
              WidgetSpan(
                  alignment: PlaceholderAlignment.middle,
                  child: SizedBox(
                    width: 120,
                    height: 50,
                    child: Card(child: Center(child: Text("Hello World!"))),
                  )),
              TextSpan(text: "the best!"),
            ])),
            Divider(),
            RichText(
              text: TextSpan(
                  style: TextStyle(color: Colors.blueGrey, fontSize: 26),
                  text: "AA",
                  children: [
                    WidgetSpan(
                        child: Text("BB",
                            style: TextStyle(
                              fontSize: 30,
                              color: Colors.blueGrey,
                            )),
                        alignment: PlaceholderAlignment.middle),
                    TextSpan(
                        text: "www.163.com",
                        style: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 34)),
                  ]),
            ),
            Divider(),
            RichText(
              text: TextSpan(
                  style: TextStyle(color: Colors.blueGrey, fontSize: 26),
                  children: [
                    WidgetSpan(
                        child: CircleAvatar(
                          backgroundImage: NetworkImage(
                            "https://image.querydata.org/movie/poster/1609307963271-0fe391.jpg",
                          ),
                          radius: 16,
                        ),
                        alignment: PlaceholderAlignment.middle),
                    TextSpan(
                        text: "流浪地球",
                        style: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 34)),
                    WidgetSpan(
                        child: Text("1982",
                            style: TextStyle(color: Colors.grey, fontSize: 18)),
                        alignment: PlaceholderAlignment.bottom)
                  ]),
            ),
            Divider(),
          ],
        ),
      ),
    );
  }
}
